package guiElements;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.metal.MetalBorders;

public class ColorSelector extends JPanel {

	private int colorR, colorG, colorB;
	private String colorName;
	private JCheckBox colorCheckBox;
	private JButton colorButton;

	/**
	 * Create the panel.
	 */
	public ColorSelector(String colorName, int colorR, int colorG, int colorB) {
		this.colorName = colorName;
		this.colorR = colorR;
		this.colorG = colorG;
		this.colorB = colorB;
		this.setLayout(null);
		this.setSize(new Dimension(200, 40));
		this.setBackground(Color.white);

		colorButton = new JButton();
		colorButton.setBackground(new Color(colorR, colorG, colorB));
		colorButton.setBorder(new BevelBorder(BevelBorder.RAISED, Color.gray,
				Color.black));
		colorButton.setSize(new Dimension(25, 25));
		colorButton.addActionListener(new ColorButtonListener());
		this.add(colorButton);
		colorCheckBox = new JCheckBox(colorName);
		colorCheckBox.setFont(new Font("Georgia", Font.PLAIN, 16));
		colorCheckBox.setBackground(Color.white);
		colorCheckBox.setLocation(new Point(25, 0));
		colorCheckBox.setSize(new Dimension(175, 40));
		this.add(colorCheckBox);

	}

	public String colorSelected() {
		if (colorCheckBox.isSelected()) {
			return colorName;
		} else {
			return null;
		}

	}

	public String getColorName() {
		return colorName;
	}

	public void setColorName(String colorName) {
		this.colorName = colorName;
	}

	public JCheckBox getColorCheckBox() {
		return colorCheckBox;
	}

	public void setColorCheckBox(JCheckBox colorCheckBox) {
		this.colorCheckBox = colorCheckBox;
	}

	private class ColorButtonListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == colorButton) {
				if (colorCheckBox.isSelected()) {
					colorCheckBox.setSelected(false);
				} else
					colorCheckBox.setSelected(true);
			}
		}

	}

}
